home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FWRITE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  722 b   |  22 lines

  1. /*  fwrite.c, from p. 439 of Turbo C Bible  */
  2. #include <stdio.h>
  3. char buffer[80] = "Testing fwirte\n\This is the second line.\n";
  4. main()
  5. {
  6.     int numwrite;
  7.     FILE *infile;
  8.     char filename[80];
  9.     printf("Enter name of a file to write to: ");
  10.     gets(filename);
  11.                 /*  Open the file for writing  */
  12.     if ((infile = fopen(filename, "wb")) == NULL)
  13.     {
  14.     printf("fopen failed.\n");
  15.     exit(0);
  16.     }
  17.                 /*  Write 80 characters and display the  */
  18.                 /*  buffer                               */
  19.     numwrite = fwrite((void *)buffer, sizeof(char), 80, infile);
  20.     printf("%d characters written to file %s\n", numwrite, filename);
  21.     printf("use 'TYPE %s' to see if it worked\n", filename);
  22. }